package com.future;

import java.util.HashMap;
import java.util.Map;

/**
 * Description: 1118. 一月有多少天
 * 1.普通年能被4整除且不能被100整除的为闰年。(例:1900/400=4.75,2000/400=5,那么1900年是平年,2000年是闰年。)
 * 2.世纪年能被400整除的是闰年。(如2000年是闰年,1900年不是闰年)
 * 1583 <= year <= 2100
 * 1 <= month <= 12
 *
 * @author weiruibai.vendor
 * Date: 2022/7/5 10:59
 */
public class Solution_1118 {

    public static void main(String[] args) {
        System.out.println(numberOfDays(1992, 7));
        System.out.println(numberOfDays(2000, 2));
        System.out.println(numberOfDays(1990, 2));
    }

    public static int numberOfDays(int year, int month) {
        Map<Integer, Integer> map = buildMonth2Days();
        if (month != 2) {
            return map.get(month);
        } else {
            // 是否是闰年
            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
                return 29;
            } else {
                return 28;
            }
        }

    }

    private static Map<Integer, Integer> buildMonth2Days() {
        Map<Integer, Integer> monthDaysMap = new HashMap<>();
        monthDaysMap.put(1, 31);
        monthDaysMap.put(3, 31);
        monthDaysMap.put(4, 30);
        monthDaysMap.put(5, 31);
        monthDaysMap.put(6, 30);
        monthDaysMap.put(7, 31);
        monthDaysMap.put(8, 31);
        monthDaysMap.put(9, 30);
        monthDaysMap.put(10, 31);
        monthDaysMap.put(11, 30);
        monthDaysMap.put(12, 31);
        return monthDaysMap;
    }

}
